$(document).ready(function(){
	var trArray = ["a","b","c","d","e"];
	var pageNumber0 = 0;
	var pageNumber1 = 0;
	var pageNumber2 = 0;
	var pageNumber3 = 0;	
	var selectCTHID;  //这个记录此时被选中的渔获物，在分页时用到
	
	function updateTool(data){
		$("#toolTable").css({"display":"table"});
		$("#addTool").css({"display":"none"});
		 $("#toolTable td").each(function(i,n){
			 if(i>7) return;
			 $(this).html(data[i]);
		 });
	}
	
	function clearAllCTHData(tableID){
		var select;
        for(var i = 0;i < 5;i++){
        	select = trArray[i];
        	$("#"+select+" td").each(function(i,n){
        		if(i <= 4){
        			$(this).html("");
        		}
        	});
        	$("#"+select+" button").each(function(i,n){
        		$(this).css({"display":"none"});
        	});
        }
	}
	
	function clearAllFSSData(){
		var select;
		for(var j = 0;j < 5;j++){
			select = trArray[j];
			$("#Fishes #"+select+" td").each(function(i,n){
				if(i <= 4)
				$(this).html("");
			});
			$("#Fishes #"+select+" button").each(function(i,n){
        		$(this).css({"display":"none"});
        	});
		}
	}
	
	function clearAllFSEData(){
		var select;
		for(var j = 0;j < 5;j++){
			select = trArray[j];
			$("#FishEggs #"+select+" td").each(function(i,n){
				if(i <= 5)
				$(this).html("");
			});
			$("#FishEggs #"+select+" button").each(function(i,n){
        		$(this).css({"display":"none"});
        	});
		}
	}
	
//	<--------------------------孙梦海增加------------------------------->
	function clearAllPFEAData(){
			$("#pfea tr:not(tr:eq(0))").remove();
	}
	function addPFEAData(data,pname){
		var dataArray = [];
		var PFEAData = [];
		dataArray = data.split("_");
		for(var j = 0; j < 5; j++){
			PFEAData = dataArray[j].split(",");
//			alert(PFEAData);
			$("#pfea").append(
					  "<tr>"+
					  "<td id='left' class='name'>"+pname+":"+PFEAData[0]+"</td>"+
					  "<td>"+PFEAData[1]+"</td>"+
					  "<td>"+PFEAData[4]+"</td>"+
					  "<td>"+PFEAData[3]+"</td>"+
					  "<td>"+
					  "<button id='showphoto'class='seephoto btn1 btn-primary'>查看</button>"+
					  "</td>"+
					  "<td>"+
					  "<button id='alter'class='update btn1 btn-primary'>修改</button>"+
					  "&nbsp;<button id='delete'class='delete btn1 btn-danger'>删除</button>"+
					  "</td>"+
					  "</tr>");
		}
	}
//	<--------------------------孙梦海增加------------------------------->
	
	function addCTHData(data){
		var dataArray = [];
		var CTHData = [];
		dataArray = data.split("_");
		for(var j = 0; j < dataArray.length; j++){
			CTHData = dataArray[j].split(",");
			$("#"+trArray[j]+" td").each(function(i,n){
				if(i>=5) return;
		    	if(i==0||i==1) {$(this).html(CTHData[i]); return;}
		    	$(this).html(CTHData[i+1]);
			});
		    
			$("#"+trArray[j]+" button").each(function(i,n){
        		$(this).css({"display":"inline-block"});
        	});
		}
	}
	
	function addFSSData(data){
		var dataArray = [];
		var FSSData = [];
		dataArray = data.split("_");
		for(var j = 0; j < dataArray.length; j++){
			FSSData = dataArray[j].split(",");
			$("#Fishes #"+trArray[j]+" td").each(function(i,n){
				 if(i >= 5) return;
		    	  if(i == 0 ) {$(this).html(FSSData[i]); return;}
		    	  else $(this).html(FSSData[i+1] );
			});
		    
			$("#Fishes #"+trArray[j]+" button").each(function(i,n){
				console.log("                "+i);
        		$(this).css({"display":"inline-block"});
        	});
		}
	}
	
	function addFSEData(data){
		var dataArray = [];
		var FSEData = [];
		dataArray = data.split("_");
		for(var j = 0; j < dataArray.length; j++){
			FSEData = dataArray[j].split(",");
			$("#FishEggs #"+trArray[j]+" td").each(function(i,n){
		    	   if(i > 5) return;
		    	   if(i == 0 ) {$(this).html(FSEData[i]); return;}
		    	   else $(this).html(FSEData[i+1] );
			});
		    
			$("#FishEggs #"+trArray[j]+" button").each(function(i,n){
				console.log("                "+i);
        		$(this).css({"display":"inline-block"});
        	});
		}
	}
	
	
	function hideButton(div,select){
		$("#"+div+" #"+select+" button").each(function(i,n){
			$(this).css({"display":"none"});
		});
	}
	
	function showButton(div,select){
		$("#"+div+" #"+select+" button").each(function(i,n){
			$(this).css({"display":"inline-block"});
		});
	}
	
	function updateGet(data,select){
		 $("#"+select+" td").each(function(i,n){
			 if(i>4) return;
			 $(this).html(data[i]);
		 });

		 
	}
	
	function updateFish(data,select){
		$("#fishesDiv #"+select+" td").each(function(i,n){
			if(i>4) return;
			$(this).html(data[i]);
		});
	}
	
	function updateFishEggs(data,select){
		$("#FishEggsDiv #"+select).show();
		$("#FishEggsDiv #"+select+" td").each(function(i,n){
			if(i>5) return;
			$(this).html(data[i]);
		});
	}
	
	
	function insertCatche(data){
		var select="";
		for(var i = 0;i<5;i++){
			if($("#"+trArray[i]+" td:first-child").html().length==0){
				select = trArray[i];
				break;
			}
		}
		if(select=="") return;
		$("#"+select+" td").each(function(i,n){
			 if(i>4) return;
			 $(this).html(data[i]);
		 });
		
		$("#"+select+" button").each(function(i,n){
			$(this).css({"display":"inline-block"});
		});
		
		$("#"+select).show();
		
	}
	
	function insertFish(data){
		var select = "";
		for(var i = 0;i < 5; i++){
			 if($("#fishesDiv #"+trArray[i]+" td:first-child").html().length==0){
				 select = trArray[i];
					break;
			 }
		}
		if(select=="") return;
		$("#fishesDiv #"+select).show();
		$("#fishesDiv #"+select+" td").each(function(i,n){
			 if(i>4) return;
			 $(this).html(data[i]);
		 });
		
		$("#fishesDiv #"+select+" button").each(function(i,n){
			$(this).css({"display":"inline-block"});
		});
	}
	
	function insertFishEggs(data){
		var select = "";
		for(var i = 0;i <= 5; i++){
			 if($("#FishEggsDiv #"+trArray[i]+" td:first-child").html().length==0){
				 select = trArray[i];
					break;
			 }
		}
		if(select=="") return;
		$("#FishEggsDiv #"+select).show();
		$("#FishEggsDiv #"+select+" td").each(function(i,n){
			 if(i>5) return;
			 $(this).html(data[i]);
		 });
		showButton("FishEggsDiv",select);
	}
	
	
	function deleteNode(ID){
	 	var url = "DeleteMonit.action";
	    if(confirm("您确定删除该条数据吗？")){
	    	////接口
	    	var par = {};
	    	par["monitID"]=ID;
	 	    $.ajax({
				   	  type:"post",
					  async:true,
					  url:url,
					  data:par,
					  success:function(result){
						  if(result=="error"){
							  alert("删除失败！");
						  }else{
							  alert("删除成功！");
							  $("#toolTable").css({"display":"none"});
							  $("#addTool").css({"display":"inline-block"});
						  }
					  }
			   });
	    }
	}
	
	
	
	
	$("#addTool").click(function(){
		$(".title").text("添加网具");
		$("#toolSumbit").text("确认提交");
		$("#showTool").css({"display":"block"});
	});
	
	$("#closeTool").click(function(){
		$("#showTool").css({"display":"none"});

	});	
	
	$("#addGet").click(function(){
		$(".title").text("添加渔获物");
		$("#getSumbit").text("确认提交");
		$("#showGet").css({"display":"block"}) ;
		
        $("#showGet input").each(function(i,n){
	        	$(this).val("");
        });
	});
	
	$("#closeGet").click(function(){
		$("#showGet").css({"display":"none"});

	});
	
	$("#closeFishes").click(function(){
		$("#showFish").css({"display":"none"});
	});
	
	$("#closeFishEggs").click(function(){
		$("#showFishEggs").css({"display":"none"});
	});
	
	var toolID;
	$("#updateTool").click(function(){
		$(".title").text("修改网具信息");
		$("#toolSumbit").text("确认修改");
		$("#showTool").css({"display":"block"});
		var Mon = [];
		
		 $("#toolTable td").each(function(i,n){
			 if(i>7) return;
			 Mon[i] = $(this).html();
		 });
		 toolID = Mon[0];
		 $("#showTool input").each(function(i,n){
			 if(i>6) return;
			 $(this).val(Mon[i+1]);
		 });
	});
	
	var getID;
	var trID;
	
	$(document).on("click","#updateGet,#updateGet1,#updateGet2,#updateGet3,#updateGet4",function(){
		$(".title").text("修改渔获物信息");
		var substring = $(this).attr("ID").substring(9,10);
		var index ;
		if(substring == null) index=0;
		else index = Number(substring);
		var selectTr = trArray[index];
		if($("#"+selectTr+" td:first-child").html().length == 0) return;
		trID = selectTr;
		console.log(selectTr+"                  =======================  "+substring);
		$("#getSumbit").text("确认修改");
		$("#showGet").css({"display":"block"});
		var Mon = [];
		 $("#"+selectTr+" td").each(function(i,n){
			 if(i>4) return;
			 Mon[i] = $(this).html();
		 });
         getID = Mon[0];
         $("#showGet input").each(function(i,n){
			 if(i>3) return;
			 $(this).val(Mon[i+1]);
		 });
	});
    
	$(document).on("click","#getDelete0,#getDelete1,#getDelete2,#getDelete3,#getDelete4",function(){
		var substring = $(this).attr("ID").substring(9,10);
		var index ;
        index = Number(substring);
		var selectTr = trArray[index];
		var ID = $("#"+selectTr+" td:first-child").html();
		var url = "DeleteMonit.action";
		if(ID.length == 0) return;
		var par = {};
    	par["monitID"]=ID;
    	 if(confirm("您确定删除该条数据吗？")){
 	    $.ajax({
			   	  type:"post",
				  async:true,
				  url:url,
				  data:par,
				  success:function(result){
					  if(result=="error"){
						  alert("删除失败！");
					  }else{
						  alert("删除成功3！");
						  var data= [];
						  var target="";
						  for(var i = 0;i<trArray.length; i++){
							  if($("#"+trArray[i]+" td:first-child").html().length == 0){ 
								  target = trArray[i-1];
								  if(target==selectTr){
									  $("#"+target+" td").each(function(i,n){
										  if(i>4) return;
										  $(this).html("");
									  });
									  $("#catchesTable"+target+" button").each(function(i,n){
										  $(this).css({"display":"none"});
									  })
									  $("#catchesTable"+target).hide();
									  return;
							       }  
							  break;
							  }
						  }
						  if(target.length == 0) target="e";
						  $("#"+target+" td").each(function(i,n){
							  if(i>4) return;
							  data[i] = $(this).html();
							  $(this).html("");
						  });
						  $("#"+target).hide();
						  updateGet(data,selectTr);
						  //$("#FishEggsDiv").hide();\
						  alert("aa");
						  $("#fishesDiv").css({"display":"none"});
						  $("#FishEggsDiv").css({"display":"none"});

					  } 
				  }
		   });
    	 }
		
	});
	
	
	$(document).on("click","#seeFishes0,#seeFishes1,#seeFishes2,#seeFishes3,#seeFishes4",function(){
		var substring = $(this).attr("ID").substring(9,10);
		var index ;
        index = Number(substring);
		var selectTr = trArray[index];
		var ID = $("#"+selectTr+" td:first-child").html();
		if(ID.length == 0) return;
		selectCTHID = ID;
		for(var j = 0; j < 5; j++){
			$("#Fishes #"+trArray[j]+" td").each(function(i,n){
				if(i > 4) return;
				$(this).html("");
			});
			$("#Fishes #"+trArray[j]).hide();
		}
		$("#Fishes button").each(function(i,n){
			$(this).css({"display":"none"});
		});
    	$.ajax({
			 type:"get",
			  async:true,
			  url:"AllMonit.action?monitID="+ID,
			  success:function(result){
				 if(result=="00"){
					  alert("发生错误，请稍后再试！")
					  return;
				  }else if(result==""||result==null){
					  alert("没有数据");
				  }else{
				  MonitArr=result.split(',');
				 
				  $("#fishesDiv").css({"display":"block"});
				  for(var i = 0;i < MonitArr.length; i++)
				 {
				   var select = trArray[i];
				   if(MonitArr[i].substring(0,3) == "FSE") return;
				   $.ajax({
					  type:"get",
					  url:"ShowMessage.action?monitID="+MonitArr[i],
					  async:false,
					  success:function(result){
					       var Mon = result.split(",");
							$("#fishesDiv #"+select).show();
					       $("#fishesDiv #"+select+" td").each(function(i,n){
					    	   if(i > 4) return;
					    	   if(i == 0 ) {$(this).html(Mon[i]); return;}
					    	   else $(this).html(Mon[i+1] );
					       });
					       
					       $("#fishesDiv #"+select+" button").each(function(i,n){
					    	     $(this).css({"display":"inline-block"});
					       });
					       
					  }
				  });
				 }
				  
				}
			  }
		  });
	});
	
	$(document).on("click","#seeFishEgg0,#seeFishEgg1,#seeFishEgg2,#seeFishEgg3,#seeFishEgg4",function(){
		var substring = $(this).attr("ID").substring(10,11);
		var index ;
        index = Number(substring);
		var selectTr = trArray[index];
		var ID = $("#"+selectTr+" td:first-child").html();
		if(ID.length == 0) return;
		selectCTHID = ID;
		for(var j = 0;j < 5;j++){
			$("#FishEggsDiv #"+trArray[j]+" td").each(function(i,n){
		    	   if(i > 5) return;
		    	   $(this).html("");
		    });
			$("#FishEggsDiv #"+trArray[j]).hide();
		}
		$("#FishEggs button").each(function(i,n){
	    	   $(this).css({"display":"none"});
	    });
	 	$.ajax({
			 type:"get",
			  async:true,
			  url:"AllMonit.action?monitID="+ID,
			  success:function(result){
				 if(result=="00"){
					  alert("发生错误，请稍后再试！")
					  return;
				  }else if(result==""||result==null){
					  alert("没有数据");
				  }else{
				  MonitArr=result.split(',');
				 
				  $("#FishEggsDiv").css({"display":"block"});
				  $("#FishEggs  button").each(function(i,n){
			    	  $(this).css({"display":"none"});

			       });
				  var j = 0;
				  for(var i = 0;i < MonitArr.length; i++)
				 {
				   if(MonitArr[i].substring(0,3) == "FSS") continue;
				   var select = trArray[j++];
				   $.ajax({
					  type:"get",
					  url:"ShowMessage.action?monitID="+MonitArr[i],
					  async:false,
					  success:function(result){
					       var Mon = result.split(",");
							$("#FishEggsDiv #"+select).show();
							console.log("aaaaaaaaaaaaaaa  "+Mon);
					       $("#FishEggsDiv #"+select+" td").each(function(i,n){
					    	   if(i > 5) return;
					    	   if(i == 0 ) {$(this).html(Mon[i]); return;}
					    	   else $(this).html(Mon[i+1] );
					       });
					       $("#FishEggsDiv #"+select+" button").each(function(i,n){
						    	  $(this).css({"display":"inline-block"});
					       });
					  }
				  });
				 }
				  
				}
			  }
		  });
	});
	
	
	var fatherFishId;
	$(document).on("click","#addFishes,#addFishes1,#addFishes2,#addFishes3,#addFishes4",function(){
		$(".title").text("添加鱼样本");
		var substring = $(this).attr("ID").substring(9,10);
		var index ;
        index = Number(substring);
		var selectTr = trArray[index];
		var ID = $("#"+selectTr+" td:first-child").html();
		if(ID.length == 0) return;
		fatherFishId = ID;
		$("#showFish").css({"display":"block"}) ;
		$("#showFish input").each(function(i,n){
			$(this).val("");
		});
		$("#sumbitFishes").text("确认提交");

	});
	var fatherFishId1;
	$(document).on("click","#addFishEgg0,#addFishEgg1,#addFishEgg2,#addFishEgg3,#addFishEgg4",function(){
		$(".title").text("添加卵样本");
		var substring = $(this).attr("ID").substring(10,11);
		var index ;
        index = Number(substring);
		var selectTr = trArray[index];
		var ID = $("#"+selectTr+" td:first-child").html();
		if(ID.length == 0) return;
		fatherFishId1 = ID;
		$("#showFishEggs").css({"display":"block"}) ;
		$("#showFishEggs input").each(function(i,n){
			$(this).val("");
		});
		$("#sumbitFishEggs").text("确认提交");
	});
	
	$(document).on("click","#updateFish0,#updateFish1,#updateFish2,#updateFish3,#updateFish4",function(){
		$(".title").text("修改鱼样本信息");
		var substring = $(this).attr("ID").substring(10,11);
		var index ;
		index = Number(substring);
		var selectTr = trArray[index];
		trID = selectTr;
		if($("#fishesDiv #"+selectTr+" td:first-child").html().length == 0) return;
		$("#sumbitFishes").text("确认修改");
		$("#showFish").css({"display":"block"}) ;
		var Mon = [];
		 $("#fishesDiv #"+selectTr+" td").each(function(i,n){
			 if(i>4) return;
			 Mon[i] = $(this).html();
		 });
        getID = Mon[0];
        $("#showFish input").each(function(i,n){
			 if(i>4) return;
			 $(this).val(Mon[i+1]);
		 });
	});
	
	
	
	$(document).on("click","#updateFishEggs0,#updateFishEggs1,#updateFishEggs2,#updateFishEggs3,#updateFish4Eggs",function(){
		$(".title").text("修改卵样本信息");
		var substring = $(this).attr("ID").substring(14,15);
		var index ;
		index = Number(substring);
		var selectTr = trArray[index];
		trID = selectTr;
		if($("#FishEggsDiv #"+selectTr+" td:first-child").html().length == 0) return;
		$("#sumbitFishEggs").text("确认修改");
		$("#showFishEggs").css({"display":"block"}) ;
		var Mon = [];
		 $("#FishEggsDiv #"+selectTr+" td").each(function(i,n){
			 if(i>5) return;
			 Mon[i] = $(this).html();
		 });
        getID = Mon[0];
        $("#showFishEggs input").each(function(i,n){
			 if(i>5) return;
			 $(this).val(Mon[i+1]);
		 });
	});
	
	
	$(document).on("click","#fishDelete0,#fishDelete1,#fishDelete2,#fishDelete3,#fishDelete4",function(){
		var substring = $(this).attr("ID").substring(10,11);
		var index ;
		var par = {};
		index = Number(substring);
		var selectTr = trArray[index];
		var ID = $("#fishesDiv #"+selectTr+" td:first-child").html();
		if(ID.length == 0) return;
		par["monitID"]=ID;
     	 if(confirm("您确定删除该条数据吗？")){
  	    $.ajax({
 			   	  type:"post",
 				  async:true,
 				  url:"DeleteMonit.action",
 				  data:par,
 				  success:function(result){
 					  if(result=="error"){
 						  alert("删除失败！");
 					  }else{
 						  alert("删除成功！");
 						  var data= [];
 						  var target="";
 						  for(var i = 0;i<trArray.length; i++){
 							  if($("#fishesDiv #"+trArray[i]+" td:first-child").html().length == 0){ 
 								  target = trArray[i-1];
 								  if(target==selectTr){
 									  $("#fishesDiv #"+target+" td").each(function(i,n){
 										  if(i>4) return;
 										  $(this).html("");
 									  });
 									 $("#fishesDiv #"+target+" button").each(function(i,n){
 										 $(this).css({"display":"none"});
 									 });
 									 $("#fishesDiv #"+target).hide();
 									 return;
 								  }  
 							  break;
 							  }
 						  }
 						  if(target.length == 0) target="e";
 						  $("#fishesDiv #"+target+" td").each(function(i,n){
 							  if(i>4) return;
 							  data[i] = $(this).html();
 							  $(this).html("");
 						  });
 						 $("#fishesDiv #"+target+" button").each(function(i,n){
								 $(this).css({"display":"none"});
						  });
 						 $("#fishesDiv #"+target).hide();
 						 updateFish(data,selectTr);
 					  } 
 				  }
 		   });
     	 }
	});
	
	
	$(document).on("click","#fishEggsDelete0,#fishEggsDelete1,#fishEggsDelete2,#fishEggsDelete3,#fishEggsDelete4",function(){
		var substring = $(this).attr("ID").substring(14,15);
		var index ;
		var par = {};
		index = Number(substring);
		var selectTr = trArray[index];
		var ID = $("#FishEggsDiv #"+selectTr+" td:first-child").html();
		if(ID.length == 0) return;
		par["monitID"]=ID;
     	 if(confirm("您确定删除该条数据吗？")){
  	    $.ajax({
 			   	  type:"post",
 				  async:true,
 				  url:"DeleteMonit.action",
 				  data:par,
 				  success:function(result){
 					  if(result=="error"){
 						  alert("删除失败！");
 					  }else{
 						  alert("删除成功！");
 						  var data= [];
 						  var target="";
 						  for(var i = 0;i<trArray.length; i++){
 							  if($("#FishEggsDiv #"+trArray[i]+" td:first-child").html().length == 0){ 
 								  target = trArray[i-1];
 								  if(target==selectTr){
 									  $("#FishEggsDiv #"+target+" td").each(function(i,n){
 										  if(i>5) return;
 										  $(this).html("");
 										  return;
 									  });
 									 $("#FishEggsDiv #"+target).hide();
 									 hideButton("FishEggsDiv",target);
 							      }  
 							  break;
 							  }
 						  }
 						  if(target.length == 0) target="e";
						  $("#FishEggsDiv #"+target).hide();
 						  $("#FishEggsDiv #"+target+" td").each(function(i,n){
 							  if(i>5) return;
 							  data[i] = $(this).html();
 							  $(this).html("");
 						  });
						 hideButton("FishEggsDiv",target);
 						 updateFish(data,selectTr);
 					  } 
 				  }
 		   });
     	 }
	});
	
	$("#getSumbit").click(function(){
		
		 var data = [];
		 var sub = "";
		 var  url="op_catch.action";
		 var formData  = new FormData($("#testGet")[0]);
         if($("#PhotoGet").val().length>100||$("#PhotoGet").val().length<=0) formData.append("isNull","");
          else formData.append("isNull","有");
         if($(this).text()=="确认提交"){
        	 sub="添加";
        	 formData.append( "flag", "insert"); 
 		     formData.append( "ID_WaterLayer",fatherID);
         }else{
        	 sub="修改";
     	    formData.append( "flag", "update"); 
            formData.append( "SampleID",getID);
         }
         
      	 $.ajax({  
         	  url:url,
         	  type: 'POST',  
               data: formData,  
               async: true,  
               cache: false,  
               contentType: false,  
               processData: false,  
               success: function (result) {
              	 if(result=="error"){
  					  alert(sub+"失败！");
  				  }else if(result=="null") {
					  alert("请填写必填项！");
				  }else{
  					  alert(sub+"成功！");
  					$("#showGet").css({"display":"none"});
  					 var array = result.split(",");
  					  data[0] = getID;
  					 $("#showGet input").each(function(i,n){
  						   if(i==4){ return;}
					    	data[i+1] = $(this).val();
					    	
						});
 					  if(sub == "添加"){ 	data[0] = array[0];	insertCatche(data); return;}
 					 updateGet(data,trID);
 					toolImages = result.split("|");
  				  }            
              }         
         });
		 
	});
	
	$("#sumbitFishes").click(function(){
		var data = [];
		 var sub = "";
		 var url="op_fish.action";
		 var formData  = new FormData($("#testFishes")[0]);
		 var sub;
        if($("#PhotoFish").val().length>100||$("#PhotoFish").val().length<=0) formData.append("isNull","");
         else formData.append("isNull","有");
        if($(this).text()=="确认提交"){
        	formData.append("flag","insert");
        	sub = "添加";
            formData.append("ID_Catches",fatherFishId);
        }else{
        	sub = "修改";
        	 formData.append( "flag", "update"); 
             formData.append( "SampleID",getID);
        }
		 $.ajax({  
	       	  url:url,
	       	  type: 'POST',  
	             data: formData,  
	             async: true,  
	             cache: false,  
	             contentType: false,  
	             processData: false,  
	             success: function (result) {  
	             	
	             	 if(result=="error"){
							  alert(sub+"失败");
						  }else if(result=="null") {
							  alert("请填写必填项！");
						  }else{
							    alert(sub+"成功");
							    data[0] = getID;
							    $("#showFish input").each(function(i,n){
							    	if(i>4) return;
							    	data[i+1] = $(this).val();
							    });
			  					$("#showFish").css({"display":"none"});
							    if(sub == "添加"){
							    data[0] = result;
							    insertFish(data);
							    return;
							    }else{
							    	updateFish(data,trID);
							    }
                                
						  } 
	             	
	             }
	       });
	});
	
	$("#sumbitFishEggs").click(function(){
		var data = [];
		 var url="op_egg.action";
		 var formData  = new FormData($("#testFishEggs")[0]);
		 var sub;
        if($("#PhotoEgg").val().length>100||$("#PhotoEgg").val().length<=0) formData.append("isNull","");
         else formData.append("isNull","有");
        if($(this).text()=="确认提交"){
        	formData.append("flag","insert");
        	sub = "添加";
            formData.append("ID_Catches",fatherFishId1);
        }else{
        	sub = "修改";
        	 formData.append( "flag", "update"); 
             formData.append( "SampleID",getID);
        }
		 $.ajax({  
	       	  url:url,
	       	  type: 'POST',  
	             data: formData,  
	             async: true,  
	             cache: false,  
	             contentType: false,  
	             processData: false,  
	             success: function (result) {  
	             	
	             	 if(result=="error"){
							  alert(sub+"失败");
						  }else if(result=="null") {
							  alert("请填写必填项！");
						  }else{
							    alert(sub+"成功");
							    data[0] = getID;
							    $("#showFishEggs input").each(function(i,n){
							    	if(i>4) return;
							    	data[i+1] = $(this).val();
							    });
			  					$("#showFishEggs").css({"display":"none"});
							    if(sub == "添加"){
							    data[0] = result;
							    insertFishEggs(data);
							    return;
							    }else{
							    	updateFishEggs(data,trID);
							    }
                                
						  } 
	             	
	             }
	       });
	});
	
	$("#toolSumbit").click(function(){
		 var data = [];
		 var sub = "";
		 var  url="op_catools.action";
         var formData  = new FormData($("#testTool")[0]);
         if($("#toolPhoto").val().length>100||$("#toolPhoto").val().length<=0) formData.append("isNull","");
          else formData.append("isNull","有");
         if($(this).text()=="确认提交"){
        	 sub="添加";
        	 formData.append( "flag", "insert"); 
             formData.append( "ID_WaterLayer",fatherID);
         }else{
        	 sub="修改";
         formData.append( "flag", "update"); 
         formData.append( "SampleID",toolID);
         }
    	 $.ajax({  
          	  url:url,
          	  type: 'POST',  
                data: formData,  
                async: true,  
                cache: false,  
                contentType: false,  
                processData: false,  
                success: function (result) {
               	 if(result=="error"){
   					  alert(sub+"失败！");
   				  }else if(result=="null") {
					  alert("请填写必填项！");
				  }else{
   					  alert(sub+"成功！");
   					$("#showTool").css({"display":"none"});
   					  var array = result.split(",");
   					  data[0] = toolID;
   					 $("#showTool input").each(function(i,n){
   						   if(i==7){ return;}
					    	data[i+1] = $(this).val();
					    	
						});

   					 
  					  if(sub == "添加"){$("#showTool").css({"display":"none"}); ;data[0] = array[0];updateTool(data);toolImages = array[1].split("|"); return;}
  					updateTool(data);
  					toolImages = result.split("|");
   				  }            
               }         
          });
	});
	
	$("#toolDelete").click(function(){
		var ID = $(".toolID").html();
		deleteNode(ID);
	});
	
	$("#catchesNext").click(function(){
		$.ajax({
		   	  type:"post",
			  async:true,
			  url:"QueryData.action",
			  data:{
				  "flag":"CTH",
				  "pageNumber":++pageNumber0,
				  "monitID":selectWLE
			  },
			  success:function(result){
				  if(result == "没有数据了"){
					  alert(result);
					  pageNumber0--;
				  }else{
					  clearAllCTHData("catchesTable");
					  addCTHData(result);
				  }
			  }
	   
		}
		);
	});
	
	$("#catchesLast").click(function(){
		if(pageNumber0 == 0){alert("这是第一页");return;}
		$.ajax({
		   	  type:"post",
			  async:true,
			  url:"QueryData.action",
			  data:{
				  "flag":"CTH",
				  "pageNumber":--pageNumber0,
				  "monitID":selectWLE
			  },
			  success:function(result){
				  if(result == "没有数据了"){
					  alert(result);
					  pageNumber0++;
				  }else{
					  clearAllCTHData("catchesTable");
					  addCTHData(result);
				  }
			  }
	   
		}
	  );
	});
	
	$("#fishesNext").click(function(){

		$.ajax({
		   	  type:"post",
			  async:true,
			  url:"QueryData.action",
			  data:{
				  "flag":"FSS",
				  "pageNumber":++pageNumber1,
				  "monitID":selectCTHID
			  },
			  success:function(result){
				  if(result == "没有数据了"){
					  alert(result);
					  pageNumber1--;
				  }else{
					  clearAllFSSData();
					  addFSSData(result);
				  }
			  }
	   
		}
		);
		
	});
	
	$("#fishesLast").click(function(){
		if(pageNumber1 == 0){alert("这是第一页");return;}
		$.ajax({
		   	  type:"post",
			  async:true,
			  url:"QueryData.action",
			  data:{
				  "flag":"FSS",
				  "pageNumber":--pageNumber1,
				  "monitID":selectCTHID
			  },
			  success:function(result){
				  if(result == "没有数据了"){
					  alert(result);
					  pageNumber1++;
				  }else{
					  clearAllFSSData();
					  addFSSData(result);
				  }
			  }
	   
		}
	  );
		
	});
	
	$("#fishEggsNext").click(function(){
		
		$.ajax({
		   	  type:"post",
			  async:true,
			  url:"QueryData.action",
			  data:{
				  "flag":"FSE",
				  "pageNumber":++pageNumber2,
				  "monitID":selectCTHID
			  },
			  success:function(result){
				  if(result == "没有数据了"){
					  alert(result);
					  pageNumber2--;
				  }else{
					  clearAllFSEData();
					  addFSEData(result);
				  }
			  }
	   
		}
		);
		
	});
	
	$("#fishEggsLast").click(function(){
		if(pageNumber2 == 0){alert("这是第一页");return;}
		$.ajax({
		   	  type:"post",
			  async:true,
			  url:"QueryData.action",
			  data:{
				  "flag":"FSE",
				  "pageNumber":--pageNumber2,
				  "monitID":selectCTHID
			  },
			  success:function(result){
				  if(result == "没有数据了"){
					  alert(result);
					  pageNumber2++;
				  }else{
					  clearAllFSEData();
					  addFSEData(result);
				  }
			  }
	   
		}
	  );
	});
	
//	<--------------------------孙梦海增加------------------------------->
	var selectId;
	var pflag;
	var pname;
$("#nextPage").click(function(){
	if($(".Fname").text().substring(0,4) == "浮游动物") {pflag = "PZO";pname="优势浮游动物";}
	else if($(".Fname").text().substring(0,4) == "浮游植物") {pflag = "PPH";pname="优势浮游植物";}
	else if($(".Fname").text().substring(0,4) == "底栖生物") {pflag = "PBE";pname="优势底栖生物";}
		$.ajax({
		   	  type:"post",
			  async:true,
			  url:"QueryData.action",
			  data:{
				  "flag":pflag,
				  "pageNumber":++pageNumber3,
				  "monitID":$(".Fname").text().substring(5,$(".Fname").text().length),
			  },
			  success:function(result){
				  if(result == "没有数据了"){
					  alert(result);
					  pageNumber3--;
				  }else{
					  clearAllPFEAData();
					  addPFEAData(result,pname);
				  }
			  }
	   
		}
		);
		
	});
	
	$("#prevPage").click(function(){
		if($(".Fname").text().substring(0,4) == "浮游动物") {pflag = "PZO";pname="优势浮游动物";}
		else if($(".Fname").text().substring(0,4) == "浮游植物") {pflag = "PPH";pname="优势浮游植物";}
		else if($(".Fname").text().substring(0,4) == "底栖生物") {pflag = "PBE";pname="优势底栖生物";}
//		alert($(".Fname").text().substring(5,$(".Fname").text().length)+"---"+pflag);
		if(pageNumber3 == 0){alert("这是第一页");return;}
		$.ajax({
		   	  type:"post",
			  async:true,
			  url:"QueryData.action",
			  data:{
				  "flag":pflag,
				  "pageNumber":--pageNumber3,
				  "monitID":$(".Fname").text().substring(5,$(".Fname").text().length),
			  },
			  success:function(result){
				  if(result == "没有数据了"){
					  alert(result);
					  pageNumber3++;
				  }else{
					  clearAllPFEAData();
					  addPFEAData(result,pname);
				  }
			  }
	   
		}
	  );
	});
//	<--------------------------孙梦海增加------------------------------->
	
});